package com.ruoyi.product.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.product.domain.ProductCategory;
import com.ruoyi.product.domain.dto.CategoryDto;
import com.ruoyi.product.domain.vo.ProductCategoryDetail1Vo;
import com.ruoyi.product.domain.vo.ProductCategoryDetail2Vo;
import com.ruoyi.product.mapper.ProductCategoryMapper;
import com.ruoyi.product.service.IProductCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品分类Controller
 *
 * @author liuhizhong
 * @date 2025-07-11
 */
@RestController
@RequestMapping("/web/productCategory")
@Tag(name = "商品分类接口", description = "提供商品分类操作")
public class ProductCategoryController extends BaseController {
    @Autowired
    private IProductCategoryService productCategoryService;
    @Autowired
    private ProductCategoryMapper productCategoryMapper;

    /**
     * 查询商品分类列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询商品分类列表", description = "")
    public AjaxResult list(ProductCategory productCategory) {
        List<ProductCategory> list = productCategoryService.selectProductCategoryList(productCategory);
        return success(list);
    }

    /**
     * 一级分类商品列表
     */
    @GetMapping("/list1/detail")
    @Operation(summary = "一级分类商品列表", description = "")
    public AjaxResult list1(@RequestParam Long id) {
        List<ProductCategoryDetail1Vo> productCategoryList = productCategoryService.selectProductCategoryList1Detail(id);
        return success(productCategoryList);
    }

    /**
     * 二级商品分类列表
     */
    @GetMapping("/list2")
    @Operation(summary = "二级商品分类列表", description = "入参categoryId")
    public AjaxResult list2(@RequestParam Long parentId) {
        List<CategoryDto> productCategoryList = productCategoryMapper.selectProductCategoryList2(parentId);
        return success(productCategoryList);
    }

    /**
     * 二级分类商品列表
     */
    @GetMapping("/list2/detail")
    @Operation(summary = "二级分类商品列表", description = "")
    public AjaxResult list2Detail(@RequestParam Long id) {
        List<ProductCategoryDetail2Vo> MapList = productCategoryService.selectProductCategoryList2Detail(id);
        return success(MapList);

    }

    /**
     * 获取商品分类详细信息
     */
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取商品分类详细信息", description = "")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productCategoryService.selectProductCategoryById(id));
    }

}
